import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'


Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/recommend"
  },
  {
    path: "/recommend",
    name: "recommend",
    component: recommend

  },
  {
    path: "/singer",
    name: "singer",
    component: () => import("../views/singer.vue")
  },
  {
    path: "/rank",
    name: "rank",
    component: () => import("../views/rank.vue")
  },


  {
    path: "/videomv",
    name: "videomv",
    component: () => import("../views/videomv.vue")
  },


  {
    path: "/rank/songlistdetails",
    name: "songlistdetails",
    component: () => import("../components/rank/songlistdetails.vue")
  },

  {
    path: "/rank/singerlist",
    name: "singerlist",
    component: () => import("../components/rank/singerlist.vue")
  },

  {
    path: "/search",
    name: "search",
    component: () => import("../views/search.vue")
  },
  {
    path: "/usermessage",
    name: "usermessage",
    component: () => import("../views/usermessage.vue"),
    beforeEnter: (to, from, next) => {
      let login = window.localStorage.getItem("token");
      if (to.path == '/recommend' || !to.path == '/') {
        next()
        return
      } else {
        if (!login) {
          next("/login");
        } else {
          next()
        }
      }
    }
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../components/base/login.vue")
  },

  {
    path: "/videomv/mvlist",
    name: "mvlist",
    props: true,
    component: () => import("../components/videomv/mvlist.vue")
  },
]

const router = new VueRouter({
  routes
})

export default router
